import axios from "axios";
let domain = localStorage.getItem("domain1");

let baseDomain = ".admin.ygsport.com.cn/prod-api"
//let baseDomain = ".test-admin.ygsport.com.cn/dev-api"
if(domain == null) {
  domain = 'lzm1';
  baseDomain = ".admin.ygsport.com.cn/prod-api"
}

//let baseDomain = ".admin.ygsport.com.cn/prod-api"
// 创建axios实例
const service = axios.create({
  // axios中请求配置有baseURL选项，表示请求URL公共部分
  baseURL: "http://" + domain + baseDomain,
  // 超时
  timeout: 30000,
});

// 响应拦截器
service.interceptors.response.use(
  (res) => {
    // 未设置状态码则默认成功状态
    const code = res.data.code || 200;
    if (
      res.request.responseType === "blob" ||
      res.request.responseType === "arraybuffer"
    ){
      return res.data;
    }
    if (code === 401) {
      return Promise.reject("无效的会话，或者会话已过期，请重新登录。");
    } else if (code === 500) {
      return Promise.reject(new Error(msg));
    } else if (code !== 200) {
      return Promise.reject("error");
    } else {
      return res.data;
    }
  },
  (error) => {
    console.log("err" + error);
    return Promise.reject(error);
  }
);
export default service;
